﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Licenta1.Expressions
{
    [Serializable]
    class BooleanExpression:Expression
    {
        Expression m1, m2;
        string op;
        

        public BooleanExpression(Context con, Expression math1, string sign, Expression math2)
            : base(con)
        {
            m1 = math1;
            m2 = math2;
            op = sign;
        }

        public override object Value
        {
            get
            {
                try
                {
                    double m1 = Convert.ToDouble(this.m1.Value);
                    double m2 = Convert.ToDouble(this.m2.Value);

                    switch (op)
                    {
                        case "<": return (m1 < m2);
                        case ">": return (m1 > m2);
                        case "<=": return (m1 <= m2);
                        case ">=": return (m1 >= m2);
                        case "!=": return (m1 != m2);
                        case "==": return (m1 == m2);
                        default: return false;
                    }
                }
                catch (Exception)
                {
                    return false;
                }
            }
        }
    }
}
